home *** CD-ROM | disk | FTP | other *** search
/ PsL Monthly 1993 December / PSL Monthly Shareware CD-ROM (December 1993).iso / prgmming / dos / c / uw_1.exe / UW_TUT10.C < prev    next >
Text File  |  1992-11-02  |  22KB  |  531 lines

  1. /****************************************************************************/
  2. /* UW_TUT10.C                                                               */
  3. /*                                                                          */
  4. /* NOTE: THIS FILE IS PUBLIC DOMAIN AND MAY BE MODIFIED AND USED AT WILL    */
  5. /*                                                                          */
  6. /* Now we add the finishing touch - context sensitive help using the        */
  7. /* UltraWin/InTUItion help engine, which we call by using the "C" system    */
  8. /* call.  The help engine is created with InTUItion and requires the        */
  9. /* InTUItion libraries to make this a linkable part of your program.        */
  10. /* However, as you will see, we can call the stand-alone help program to    */
  11. /* take full advantage of this hypertext help system!                       */
  12. /*                                                                          */
  13. /*                                                         Dr. Boyd Gafford */
  14. /*                                                         Kevin Huck       */
  15. /*                                                         EnQue Software   */
  16. /*                                                         09/16/92         */
  17. /****************************************************************************/
  18. #include <stdio.h>
  19. #include <fcntl.h>
  20. #include <io.h>
  21. #ifndef __TURBOC__
  22. #include <sys\types.h>
  23. #endif
  24. #include <sys\stat.h>
  25. #include <time.h>
  26. #include <ctype.h>
  27. #include "uw.h"                           /* include the necessary headers  */
  28.  
  29. #define MAX_CUST 50
  30.  
  31. typedef struct cust
  32. {
  33.   int status;
  34.   int cust_no;
  35.   char business[34];
  36.   char name[34];
  37.   char addr[34];
  38.   char city[34];
  39.   char state[4];
  40.   char zip[10];
  41.   char phone[16];
  42.   char fax[16];
  43.   char date[10];
  44.   char memo[34];
  45.   char unused[26];                                /* round out to 256 bytes */
  46. } CUST;
  47.  
  48. /*----------------------- global window variables --------------------------*/
  49. WINDOW   Desk_wn, Window1;
  50. CUST Customers[MAX_CUST];
  51. char Fname[33];
  52.  
  53. MENU    Top_menu, *Top_mnp = &Top_menu;
  54. MENU    Files_menu, Edit_menu, Print_menu;
  55. MENU    *Drop_mnps[3];
  56.  
  57. PRINT   Print;
  58.  
  59. /*-------------------------------- prototypes ------------------------------*/
  60. int disp_time(void);
  61. void disp_cust(CUST *cp, WINDOW *wnp);
  62. int file_load(CUST *customers);
  63. int file_save(CUST *customers);
  64. int get_fname(char *fname);
  65. void print_cust(CUST *cp, PRINT *p);
  66. void do_external_help( char *cmd );
  67.  
  68. /*********/
  69. /* ~main */
  70. /*       ********************************************************************/
  71. /*  Demonstrate data entry capability...                                    */
  72. /****************************************************************************/
  73. int main()
  74. {
  75.   int i, ret_val, cust = 0, end_flag = 0, print_stat = 0;
  76.   char *search, buff[81];
  77.   WINDOW *wnp;
  78.   CUST *cp;
  79.   uchar back_att  = (LIGHTGRAY << 4) | BLACK,
  80.         bdr_att   = (LIGHTGRAY << 4) | BLACK,
  81.         csr_att   = (CYAN << 4) | YELLOW,
  82.         first_att = (LIGHTGRAY << 4) | RED;
  83.  
  84.   wnp = &Window1;                         /* set local window pointer       */
  85.   init_video(80, 25);                     /* init video for 80 x 25 screen  */
  86.   init_clock(0x3333);                     /* init clock irq at 91 tics/sec  */
  87.   init_mouse();                           /* init mouse if available        */
  88.  
  89.   wn_create(0, 0, V_cols-1, V_rows-1, NO_BDR, WN_NORMAL, &Desk_wn);
  90.   link_window(&Desk_wn);
  91.  
  92.   /*------------------------ create the menu system ------------------------*/
  93.   Drop_mnps[0] = &Files_menu;
  94.   Drop_mnps[1] = &Edit_menu;
  95.   Drop_mnps[2] = &Print_menu;
  96.  
  97.   menu_create(0, 0, V_cols - 1, 0, M_HORIZONTAL,
  98.               back_att, bdr_att, csr_att, first_att,
  99.               NO_BDR, WN_NORMAL, Top_mnp);
  100.   item_add( "   Files   ", 1, 3, &Top_menu );
  101.   item_add( "   Edit    ", 2, 3, &Top_menu );
  102.   item_add( "   Print   ", 8, 3, &Top_menu );
  103.  
  104.   menu_create(0, 1, 14, 5, M_VERTICAL,
  105.     back_att, bdr_att, csr_att, first_att,
  106.     SGL_BDR, WN_NORMAL, Drop_mnps[0]);
  107.   item_add( " Load File", 4, 1, &Files_menu );
  108.   item_add( " Save File", 5, 1, &Files_menu );
  109.   item_add( "   Quit   ", 3, 3, &Files_menu );
  110.  
  111.   menu_create(11, 1, 32, 4, M_VERTICAL,
  112.     back_att, bdr_att, csr_att, first_att,
  113.     SGL_BDR, WN_NORMAL, Drop_mnps[1]);
  114.   item_add( " Clear Current", 6, 7, &Edit_menu );
  115.   item_add( " Clear All    ", 7, 7, &Edit_menu );
  116.  
  117.   menu_create(22, 1, 43, 4, M_VERTICAL,
  118.     back_att, bdr_att, csr_att, first_att,
  119.     SGL_BDR, WN_NORMAL, Drop_mnps[2]);
  120.   item_add( " Print Current", 9, 7, &Print_menu );
  121.   item_add( " Print All    ", 10, 7, &Print_menu );
  122.  
  123.   set_idle_func(disp_time);               /* set background clock function  */
  124.  
  125.   wn_create(5, 5, 75, 20, SLD_BDR, WN_POPUP, wnp);
  126.   wn_color(YELLOW, BLUE, wnp);            /* change the window colors       */
  127.   wn_bdr_color(WHITE, BLUE, wnp);         /* change the border's colors     */
  128.   link_window(wnp);
  129.  
  130.   /*-------------- initialize first customer as EnQue Software --------------*/
  131.   cp = &Customers[0];
  132.   strcpy(cp->business, "EnQue Software"); 
  133.   strcpy(cp->name, "Kevin Huck & Boyd Gafford");  
  134.   strcpy(cp->addr, "Rt. 1 Box 116C"); 
  135.   strcpy(cp->city, "Pleasant Hill");  
  136.   strcpy(cp->state, "MO");  
  137.   strcpy(cp->zip, "64080"); 
  138.   strcpy(cp->phone, "(816)987-2515"); 
  139.   strcpy(cp->fax, "(816)987-2515");      
  140.   strcpy(cp->date, "09/11/92");      
  141.   strcpy(cp->memo, "BBS 816-358-8990"); 
  142.  
  143.   /*------------------------ initialize the printer ------------------------*/
  144.   if( init_printer("LPT1", NULL, 2048L, 2048L, &Print) )
  145.     print_stat = 1;
  146.  
  147.   Top_mnp->csr_pos = M_MAX_ENTRIES;    /* set to prevent menu from hiliting */
  148.   menu_set(Top_mnp);          /* on entry, since menu is not active until   */
  149.   Top_mnp->csr_pos = 0;       /* Alt-F, Alt-E, or Alt-P is hit              */
  150.  
  151.   wn_color(LIGHTGRAY, RED, &Desk_wn);
  152.   wn_plst(CENTERED, 3, "Use cursor keypad to select customer", &Desk_wn);
  153.   wn_plst(CENTERED, 4, "or click on cursor buttons at bottom of screen", &Desk_wn);
  154.   wn_plst(CENTERED, 21, "<Up> <Dn>  <PgUp> <PgDn>  <Home> <End>", &Desk_wn);
  155.   wn_plst(CENTERED, 22, "<<< Press Alt-H or click on desired item for help >>>", &Desk_wn);
  156.   wn_color(YELLOW, RED, &Desk_wn);
  157.   while(!end_flag)
  158.   {
  159.     cp = &Customers[cust];
  160.     mv_cs(1,1, wnp);
  161.     wn_printf(wnp, "Customer:%3d", cust+1);
  162.     disp_cust(cp, wnp);
  163.     m_show();
  164.     wait_event();
  165.     m_hide();
  166.     search = NULL;
  167.     if( Event.is_mouse )                            /* process mouse action */
  168.     {
  169.       if( range(0,Event.m_x,11) && (Event.m_y == 0) )
  170.         Event.key = KEY_ALT_F, search = "///File";
  171.       else if( range(11,Event.m_x,22) && (Event.m_y == 0) )
  172.         Event.key = KEY_ALT_E, search = "///Edit";
  173.       else if( range(22,Event.m_x,33) && (Event.m_y == 0) )
  174.         Event.key = KEY_ALT_P, search = "///Print";
  175.  
  176.       else if( range( 7,Event.m_x,47) && (Event.m_y == 9) )
  177.         Event.key = 'B', search = "///Business";
  178.       else if( range( 7,Event.m_x,47) && (Event.m_y == 10) )
  179.         Event.key = 'N', search = "///Name";
  180.       else if( range( 7,Event.m_x,47) && (Event.m_y == 11) )
  181.         Event.key = 'A', search = "///Address";
  182.       else if( range( 7,Event.m_x,47) && (Event.m_y == 12) )
  183.         Event.key = 'C', search = "///City";
  184.       else if( range(50,Event.m_x,59) && (Event.m_y == 12) )
  185.         Event.key = 'S', search = "///State";
  186.       else if( range(61,Event.m_x,71) && (Event.m_y == 12) )
  187.         Event.key = 'Z', search = "///Zip";
  188.       else if( range( 7,Event.m_x,47) && (Event.m_y == 13) )
  189.         Event.key = 'P', search = "///Phone";
  190.       else if( range( 7,Event.m_x,47) && (Event.m_y == 14) )
  191.         Event.key = 'F', search = "///Fax";
  192.       else if( range( 7,Event.m_x,47) && (Event.m_y == 15) )
  193.         Event.key = 'D', search = "///Date";
  194.       else if( range( 7,Event.m_x,47) && (Event.m_y == 16) )
  195.         Event.key = 'M', search = "///Memo";
  196.  
  197.       else if( range( 21,Event.m_x,24) && (Event.m_y == 21) )
  198.         Event.k